import time
import unittest
from appium import webdriver
from appium.options.ios import XCUITestOptions
from appium.webdriver.common.appiumby import AppiumBy

capabilities = dict(
    platformName="iOS",
    platformVersion="18.1",
    # bundleId="com.itcast.HMiOSTest",
    bundleId="com.apple.Preferences",
    deviceName="iPhone 16",
    udid="8FD9A7E6-DCD6-4E0A-9C5A-7E381BF5EA5C",
    automationName="XCUITest",
    usePrebuiltWDA=True,
    showXcodeLog=True,
    startlWDP=True,
    useXctestrunFile=False
)

appium_server_url = 'http://localhost:4723'


class TestAppium(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Remote(command_executor=appium_server_url,
                                       options=XCUITestOptions().load_capabilities(capabilities))

    def tearDown(self) -> None:
        if self.driver:
            self.driver.quit()

    def test_find_battery(self) -> None:
        time.sleep(2)
        # self.driver.find_element(by=AppiumBy.XPATH, value='//XCUIElementTypeStaticText[@name="通用"]').click()
        self.driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value="通用").click()
        time.sleep(5)


if __name__ == '__main__':
    unittest.main()
